#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>


int main()
{
    umask(0);
    // int fd = open("log.txt", O_CREAT | O_WRONLY | O_TRUNC, 0666);
    // int fd = open("log.txt", O_CREAT | O_WRONLY | O_APPEND, 0666);
    int fd = open("log.txt", O_RDONLY);
    if(fd < 0)
    {
        perror("open");
        return 1;
    }
    printf("fd: %d\n", fd);

    while(1)
    {
        char buffer[64];
        int n = read(fd, buffer, sizeof(buffer)-1);
        if(n > 0)
        {
            buffer[n] = 0;
            printf("%s", buffer);
        }
        else if(n == 0)
        {
            break;
        }
    }

    close(fd);
    return 0;
}
